<cfsilent>
	<cfset hours = $.request.getValue('hours') />
	<cfif not structKeyExists(url,'hours') || hours eq ''>
		<cfset hours = 24 />
	</cfif>
	<cfset grouped = $.run.it('logService.groupErrors',{age=hours}) />
</cfsilent>

<cfoutput>
	<cfsavecontent variable="page">
		<style>
			.errorType{
				text-align:left;
				border:1px solid ##cccccc;
				margin:4px;
				padding:4px;
			}
			.offender{
				float:right;
				color:blue;
			}
		</style>
		
		<script>
			setTimeout(function(){$('##layout-right').fadeOut();},1000);
			var Error = {
				expand:function(that){
					var $this = $(that);
					var $error = $this.closest('.errorType');
					var $details = $error.find('.details');
					if($details.hasClass('loaded')){
						if($details.hasClass('hidden')){
							$details.removeClass('hidden');
						} else {
							$details.addClass('hidden');
						}
					} else {
						$details.addClass('loaded');
						Ajax.run({
							method:"logView.renderErrorDetail",
							onsuccess:function(data){
								$details.html(data);
								$details.removeClass('hidden');
							},
							args:{
								name:$this.closest('.widget').find(".widget-form-title").text(),
								message:$this.text(),
								age:#hours#
							}
						});
					}
				},
				toggle:function(that,theClass){
					var $this = $(that);
					var $error = $this.closest('.errorType');
					var $divs = $error.find('.cfcatchDump,.argumentDump,.sessionDump').not('.'+theClass);
					$divs.addClass('hidden');
					var $div = $error.find("."+theClass);
					if($div.hasClass('hidden')){
						$div.removeClass('hidden');
					} else{
						$div.addClass('hidden');
					}
				}
			};
		</script>

		<div class="header variable-width">
			<i class="fa fa-home" onclick="Main.nav('home');"></i>
			<div class="header-title">Errors</div>
			#$.render.img(path="craftivity/widget_icons/code.png",class="title_logo")#</br>
			#$.render.form(name="filter",method="logController.filterErrors")#
				<select name="age" onchange="$('form##filter').submit();">
					<option value="1"<cfif hours eq "1">selected</cfif>>1 hour</option>
					<option value="2"<cfif hours eq "2">selected</cfif>>2 hours</option>
					<option value="12"<cfif hours eq "12">selected</cfif>>12 hours</option>
					<option value="24"<cfif hours eq 24>selected</cfif>>1 day</option>
					<cfloop list="48,96,120,168,240,336,720" index="i">
						<option value="#i#" <cfif hours eq i>selected</cfif>>#i/24# days</option>
					</cfloop>
				</select>
			</form>
		</div>
		
		<cfloop collection="#grouped#" index="local.i" item="local.item">
			<cfif structCount(local.item) gt 0>
				<div class="widget short">
					<div class="widget-form-title">
						#local.i#
					</div>
					<cfloop collection="#local.item#" index="local.j" item="local.jtem">
						<div class="errorType">
							<div class="errorName">
								<a href="javascript:void(0);" onclick="Error.expand(this);">#local.j#</a>
							</div>
							<div class="errorCount">
								<cfset date = $.date.applyLocalization(local.jtem.date) />
								<cfset diff = dateDiff('h',local.jtem.date,now())>
								(#local.jtem.count#x) #diff#hr<cfif diff gt 0>s</cfif> ago<span style="float:right;">#$.format.humanizeDate(date)# - #$.format.humanizeTime(date)#</span>
							</div>
							<div class="details hidden"></div>
						</div>
					</cfloop>
				</div>
			</cfif>
		</cfloop>
		
	</cfsavecontent>
	
	#$.run.it("craftivityView.renderPage",{centerContent=page})#
</cfoutput>